﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL_Class;

namespace NLLSite.Administrator.UserControl
{
    public partial class ChangePass : System.Web.UI.UserControl
    {
        Admin ad = new Admin();

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            DAL_Class.Administrator oa = (DAL_Class.Administrator)Session["objadmin"];
            int ID = oa.ID;
            if (txtCurrentpass.Text == oa.Password)
            {
                Label1.Text = ad.changePass(ID, GetMD5Hash(txtNewpass.Text), GetMD5Hash(txtCurrentpass.Text));
            }
            else
            {
                Label1.Text = "Mật khẩu cũ sai!";
            }
        }

        public static string GetMD5Hash(string input)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
            bs = x.ComputeHash(bs);
            System.Text.StringBuilder s = new System.Text.StringBuilder();
            foreach (byte b in bs)
            {
                s.Append(b.ToString("x2").ToLower());
            }
            string password = s.ToString();
            return password;
        }
    }
}